package hrms.service;

import hrms.dao.CandidateMapper;
import hrms.dao.RecruitmentMapper;
import hrms.entity.Candidate;
import hrms.entity.Recruitment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Service
public class CandidateService {

    @Autowired
    private CandidateMapper candidateMapper;

    @Autowired
    private RecruitmentMapper recruitmentMapper;

    public Candidate findById(Integer id){ return candidateMapper.findById(id); }

    public void insertCandidate(Candidate candidate){ candidateMapper.insertCandidate(candidate);}

    public List<Candidate> findAll(){
        List<Candidate> all = candidateMapper.findAll();
        for (Candidate candidate : all) {
            Recruitment recruitment = recruitmentMapper.findById(candidate.getRecruitment().getId());
            candidate.setRecruitment(recruitment);
        }
        return all;
    }

    public void updateRecord(Candidate candidate){
        candidateMapper.updateRecord(candidate);
    }

    public void updateStatus(Candidate candidate){
        candidateMapper.updateStatus(candidate);
    }
    // 用来修改应聘者被录取后的其他投递状态
    public void updateStatusByPhone(String phone){ candidateMapper.updateStatusByPhone(phone); };
}
